<?php
 /**
 +------------------------------------------------------------------------------
 * title
 +------------------------------------------------------------------------------
 * @Version  2.3
 * @Author   WangXian
 * @E-mail    admin@loopx.cn
 * @FileName  indexController.php
 * @Creation  date 2010-12-6 下午04:52:16
 * @Modified  date 2010-12-6 下午04:52:16
 +------------------------------------------------------------------------------
 */
class indexController
{
	function __construct()
	{
		$this->view = new View();
	}

	function indexAction()
	{
		$note = new notebookModel();
		$this->view->data = $note->list_note( getv('page',1) );
		//dump($this->view->data);
		
		//翻页导航链接
		$link = new Link( getv('page',1), $this->view->data['data_count'], U('index/index'));
		$this->view->pagelink = $link->show(3);
		
		$this->view->render();
	}
	
	public function deleteAction()
	{
		if(getv('id'))
		{
			$note = new notebookModel();
			if($note->del_note( getv('id') ))
				show_success('删除成功!');
			else
				show_error('删除失败！');
		}
		else
		{
			show_error('非法请求！', U('index/index'));
		}
	}

	public function addAction()
	{
		if(postv('title',0))
		{
			$data['title']		= htmlspecialchars(postv('title'));
			$data['content']	= htmlspecialchars(postv('content'));
			$data['created_at'] = date('Y-m-d H:i:s');
			
			//dump($data);
			$note = new notebookModel();
			if($note->add_note( $data ))
				show_success('添加成功!', U('index/index'));
			else
				show_error('添加失败！');
		}
		else
		{
			$this->view->render();
		}
	}
	
	public function editAction()
	{
		if( postv('id',0) )
		{
			$data['title']		= htmlspecialchars(postv('title'));
			$data['content']	= htmlspecialchars(postv('content'));
			
			//dump($data);
			$note = new notebookModel();
			if($note->update_note( postv('id'), $data ))
				show_success('更新成功!', U('index/detail/id/'.postv('id') ) );
			else
				show_error('更新失败！');
		}
		else if( getv('id',0) )
		{
			$note = new notebookModel();
			$this->view->data = $note->note_info(getv('id'));
			$this->view->render();
		}
		else
		{
			show_error('非法请求！', U('index/index'));
		}
	}
	
	public function detailAction()
	{
		if(getv('id'))
		{
			$note = new notebookModel();
			$this->view->data = $note->note_info(getv('id'));
			$this->view->render();
		}
		else
		{
			show_error('非法请求！', U('index/index'));
		}
	}
}

/* End of file indexController.php */
/* Location: indexController.php */